function rawtrans(){
debugger
    var inputtext=document.getElementById('inputOriginal').value.toString()
    if(escape(inputtext).indexOf("%u")!=-1 || inputtext.replace(/(^s*)|(s*$)/g, "").length ==0){
        alert("翻译文本中不能为空或含有中文！")
        return 0
    }
    var targettext=document.getElementById('targetspantext')
    targettext.innerHTML="翻译中，请稍后（登录即可享受极速引擎翻译）"
    var xhr = new XMLHttpRequest()
    var fd = new FormData()
    fd.append('text',inputtext)
    xhr.open('post','/lttranslate',true)
    xhr.onreadystatechange = function(){
        if(this.readyState==0)
            alert('翻译中，请稍后')
        if(this.readyState==4){
        debugger
            targettext.innerHTML=this.responseText
        }
    }
    xhr.send(fd)
}

function pre_login(){
    //处理蒙版和显示
    var div1 = document.getElementById('dialogCover');
    var div2 = document.getElementById('loginWindow');
    if(div1.style.display=='block'){
    	div2.style.display = "none";
    	div1.style.display = "none";
    }
    else{
    	div1.style.display = "block";
    	div2.style.display = "block";
    }
}
function name_click(){
    var dt = document.getElementById('account-cover')
    if(dt.style.display=="block")
        dt.style.display="none"
    else
        dt.style.display="block"
}
function login(){
    var user_id = document.getElementById('auto-id-1584528060607').value
    var pwd_ori = document.getElementById('auto-id-1584528060610').value
    var pwdt = hex_md5(pwd_ori)
    var fd = new  FormData()
    fd.append('id',user_id)
    fd.append('pwd', pwdt)
    var xhr = new XMLHttpRequest()
    xhr.open('post','/login',true)
    xhr.onreadystatechange = function(){
        if(this.readyState==4){
            if(this.responseText=='0')
                top.window.alert("账号或密码输入错误！")
            else
                top.window.location.href = '/index'
        }
    }
    xhr.send(fd)
}
function upfile(){
        var temp = document.getElementById('loginblock').style.display
        if(temp=="block"){
            alert("请先登录！")
            pre_login()
            return 0
        }
        var t = document.getElementById('inputselect');
		var s = document.getElementById('inputOriginal');
		var ins = document.getElementById('docUploadCon');
        var file=document.getElementsByTagName('input')[1].files[0];
        var fd=new FormData();
        var xhr=new XMLHttpRequest();
        xhr.open('post','/index',true);
        xhr.onreadystatechange=function (){
            //readystate为4表示请求已完成并就绪
            if(this.readyState==4){
		        t.style.display='none';
		        s.style.display = 'block';
		        ins.style.display = 'block';
                //document.getElementById('precent').innerHTML=this.responseText;
                //在进度条下方插入百分比
                if(this.responseText == "1"){
                	var wc = confirm("上传成功！现在去翻译？")
                	if(wc==true){
                        var tt = document.getElementById('filelistid')
                        tt.click()
                        window.location.href=tt.getAttribute('href')
                        return 0
                	}
                }
                else if(this.responseText=='2'){
                window.alert("可用次数已经用完！")
                }
                else
                	window.alert("系统异常！重新登陆或联系管理员")
                	window.location.href="/"
            }
        }
        xhr.upload.onprogress=function (ev){
            //如果ev.lengthComputable为true就可以开始计算上传进度
            //上传进度 = 100* ev.loaded/ev.total
            if(ev.lengthComputable){
                var precent=100 * ev.loaded/ev.total;
                console.log(precent);
                //更改进度条，及百分比
                document.getElementById('bar').style.width=precent+'%';
                document.getElementById('precent').innerHTML=Math.floor(precent)+"%       "+Math.floor(ev.loaded/1024)+'/'+Math.floor(ev.total/1024)+' KB';
            }
        }
        fd.append('file',file);
		t.style.display='block';
		s.style.display = 'none';
		ins.style.display = "none";
        xhr.send(fd);
      }
function delfile(file_id, block){
    var bx = document.getElementById("functiontranslate"+block.toString())
    if(bx.innerHTML=="翻译中"){
    alert("翻译中不能删除！")
    return 0
    }
    block='block'+block.toString()
    var file_block = document.getElementById(block)
    var xhr = new XMLHttpRequest()
    xhr.open('POST', '/delete/'+file_id.toString(), true)
    xhr.onreadystatechange = function(){
        if(this.readyState==4){
            if(this.responseText=="0"){
                alert("删除失败！")
                return 0
            }
            else{
                if(file_block!=undefined){
                    file_block.style.display="none";
                    alert("删除成功！")
                }
                else{
                    alert("非法操作，数据异常！")
                    window.location.href="/"
                }
            }
        }
    }
    xhr.send()
}
function getsource(fileid,filename){//下载源文件
    event.stopPropagation();
    var uid = document.getElementById('userbox').getAttribute('tet');
    var fid = fileid;
    const elink = document.createElement('a');
    elink.download = filename;
    elink.style.display = 'none';
    // elink.target = '_blank';
    elink.href = '/downsfile/'+uid.toString()+"_"+fid.toString();
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href); // 释放URL 对象
    document.body.removeChild(elink)
}
function getdstfile(fileid,filename){//下载译后文件
    debugger;
    event.stopPropagation();
    var uid = document.getElementById('userbox').getAttribute('tet');
    var fid = fileid;
    const elink = document.createElement('a');
    elink.download = filename;
    elink.style.display = 'none';
    // elink.target = '_blank';
    elink.href = '/downdfile/'+uid.toString()+"_"+fid.toString();
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href); // 释放URL 对象
    document.body.removeChild(elink)

//
//    var xhr = new XMLHttpRequest()
//    xhr.open('post','/downsfile/'+uid.toString()+"_"+fid.toString(),true)
//    xhr.onreadystatechange=function(){
//        if(this.readyState==4){
//
//        }
//    }
//    xhr.send()
}
function translatefile(fileid,i){//去翻译文件
    event.stopPropagation();
    var uid = document.getElementById('userbox').getAttribute('tet');
    var filename = fileid;
    var parameter = filename+"_"+uid
    var xhr=new XMLHttpRequest()
    var bx = document.getElementById("functiontranslate"+i.toString())
    xhr.open('POST','/translate/'+parameter,true)
    xhr.onreadystatechange=function(){
    if(this.readyState==4)
    debugger;
        if(this.responseText=='1'){
       alert("翻译成功！")
       bx.innerHTML="下载"
       bx.onclick="getdstfile("+fileid+")"
        }
        else if(this.responseText=='0')
            alert('状态异常！重新登陆或联系开发者')
    }
    xhr.send()
    alert("努力翻译中，请稍后回来查看！")
    bx.innerHTML="翻译中"
    bx.onclick="javascript:void(0);"
}
function getcode(){//验证码刷新
    var tagImg = document.getElementById('RegCodeImage');
    let xhr = new XMLHttpRequest();
    xhr.open('GET', '/userid', true);
    xhr.send();
    xhr.onreadystatechange=function (){
        if(this.readyState==4){
        tagImg.src = this.responseText;
        }
    }
}
function itemslog(){
    var tbox = document.getElementById('regsiter15221');
    if(tbox.style.display=='none'){
        tbox.style.display = "block";
    }else
        tbox.style.display = "none";
}
function inputidfocus(){
    var a = document.getElementById('usertit');
    var succtitle = document.getElementById('user-fon')
    var errotitlt = document.getElementById('user-error')
    var genetitle = document.getElementById('user-rs')
    genetitle.style.display='block';
    errotitlt.style.display='none';
    succtitle.style.display='none';
    a.style.display='block';
}
function inputidblur(){
    var a = document.getElementById('usertit');
    var uid = document.getElementById('user').value
    a.style.display='none'
    var genetitle = document.getElementById('user-rs')
    var succtitle = document.getElementById('user-fon')
    var errotitlt = document.getElementById('user-error')
    if(uid==null||uid==" "||uid.length<2||uid.length>16){
        genetitle.style.display = 'none';
    	errotitlt.style.display='block';
    	return 0;
    }else{
        genetitle.style.display = 'block';
    	errotitlt.style.display='none';
    }
    let xhr = new XMLHttpRequest()
    var  fd = new FormData()
    fd.append('user_id', uid)
    xhr.open('post', '/sureid',true)
    xhr.onreadystatechange=function(){
    	if(xhr.readyState==4){
    		if(this.responseText == "1"){
    		        genetitle.style.display = 'none';
    	            succtitle.style.display='block';
    		}
    		else{
    		        genetitle.style.display = 'none';
    	            errotitlt.style.display='block';
    		}
    	}
    }
    xhr.send(fd)
}
function inputnamefocus(){
    var a=document.getElementById('nametitle');
    var b=document.getElementById('name-rs');
        a.style.display = 'none';
        b.style.display='block';
}
function inputnameblur(){
    var name = document.getElementById('user_name').value;
    var a=document.getElementById('nametitle');
    var b=document.getElementById('name-rs');
    if(name==null||name==" "||name.length<2||name.length>8){
        a.style.display = 'block';
        b.style.display='none';
    }
    else{
            a.style.display = 'none';
        b.style.display='block';
    }
}
function inputmobilfocus(){
    var t = document.getElementById('mobiletit');
    var g = document.getElementById('mobile-rs');
    var e = document.getElementById('mobile-error');
    t.style.display='block';
    g.style.display='block';
    e.style.display = 'none';
}
function inputmobilblur(){
    var t = document.getElementById('mobiletit');
    var value = document.getElementById('mobile').value;
    var g = document.getElementById('mobile-rs');
    var e = document.getElementById('mobile-error');
    t.style.display='none';
    g.style.display='block';
    if(value==null||value==" "||value.length!=11){
        e.style.display = 'block';
        g.style.display='none';
    }
    else{
            e.style.display = 'none';
        g.style.display='block';
    }
}
function inputpwdfocus(){
    var g = document.getElementById('pwd-rs');
    var e = document.getElementById('pwd-error');
    g.style.display='block';
    e.style.display='none';
}
function inputpwdblur(){
    var value = document.getElementById('pwd').value;
    var g = document.getElementById('pwd-rs');
    var e = document.getElementById('pwd-error');
    if(value.length<6||value.length>16||value==null||value==" "){
        g.style.display='none';
        e.style.display='block';
    }else{
            g.style.display='block';
        e.style.display='none';
    }
}
function inputpassblur(){
    var value1=document.getElementById('pwd').value;
    var value2=document.getElementById('pass').value;
    var g = document.getElementById('pass-rs');
    var e = document.getElementById('pass-error');
    if(value1!=value2){
           g.style.display='none';
           e.style.display='block';
    }
    else{
                   g.style.display='block';
           e.style.display='none';
    }
}
function yzmblur(){
    var code = document.getElementById('yzm').value;
    var g = document.getElementById('yzm-rs');
    var e = document.getElementById('yzm-error');
    let xhr = new XMLHttpRequest()
    var fd =  new FormData()
    fd.append('code', code)
    xhr.open('post', '/verifycode', true)
    xhr.onreadystatechange = function(){
        if(this.readyState==4){
            if(this.responseText=='1'){
            e.style.display='none';
            g.style.display='block';
            }
            else{
                getcode();
                e.style.display='block';
                g.style.display='none';
            }
        }
    }
    xhr.send(fd)
}
function checkmail(){
　　var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
　　var obj = document.getElementById("email"); 
　　if(obj.value === ""){ 
　　　　alert("输入不能为空!");
　　　　return false;
　　}else if(!reg.test(obj.value)){ 
　　　　alert("请输入有效合法的邮箱地址！");
　　　　return false;
　　}else{
　　　　return true;
    }
}
function checkform(){
debugger;
        yzmblur()
       if(document.getElementById('user-error').style.display=="block"){
            window.alert("用户账户输入错误！");
            return 0;
       }
       if(document.getElementById('nametitle').style.display=="block"){
            window.alert("姓名输入错误！");
            return 0;
       }
       if(document.getElementById('pwd-error').style.display=="block"){
            window.alert("密码输入错误！");
            return 0;
       }
       if(document.getElementById('pass-error').style.display=="block"){
            window.alert("确认密码输入错误！");
            return 0;
       }
       if(document.getElementById('mobile-error').style.display=="block"){
            window.alert("手机号输入错误！");
            return 0;
       }
       if(document.getElementById('yzm-error').style.display=="block"){
            window.alert("验证码输入错误！");
            return 0;
       }
       if(!document.getElementById('igrai').checked){
             window.alert("请同意服务协议！");
             itemslog();
             return 0;
       }
       var form1 = document.getElementById('form1')
       var xhr = new XMLHttpRequest();
       var fd = new FormData(form1)
       ps = hex_md5(fd.get('password'))
       fd.append('pwd-hash', ps)
       fd.set('password','')
       fd.set('password2','')
       xhr.open('post', '/register', true)
       xhr.onreadystatechange=function (){
        if(this.readyState==4){
        if(this.responseText=='1'){
            alert("注册成功！请前往登录")
            window.location.href="/";
        }else{
            alert("注册失败！请尝试重新注册")
            getcode()
        }
        }
    }
       xhr.send(fd)

}
